package com.dmw.common.result;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    //状态码：200表示成功，0和其他值表示失败
    private Integer code;
    //提示信息
    private String msg;
    //返回数据
    private T data;

    //成功响应
    public static <T> Result<T> success() {
        Result<T> result = new Result();
        result.setCode(200);
        return result;
    }

    //成功响应并返回数据
    public static <T> Result<T> success(T object) {
        Result<T> result = new Result();
        result.setCode(200);
        result.setData(object);
        return result;
    }

    //响应失败
    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }
}
